package com.atguigu.tingshu.order.config;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class CancelOrderConfig {

    /**
     * 定义延迟队列交换机
     * @return
     */
    @Bean
    public CustomExchange cancelOrderExchange(){
        //   设置参数;
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER, "x-delayed-message", true, false, args);
    }

    /**
     * 延迟队列
     * @return
     */
    @Bean
    public Queue dealyQueue(){
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true, false, false);
    }

    /**
     * 绑定关系
     * @return
     */
    @Bean
    public Binding delayBinding(){
        //  return BindingBuilder.bind(dealyQueue()).to(cancelOrderExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
        return BindingBuilder.bind(dealyQueue()).to(cancelOrderExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
